<template>
  <div class="mod-fii__fiispace">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.title" placeholder="名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="backPath">返回上级</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="name" label="文件名" show-overflow-tooltip>
        <template #default="scope" @click="openFile(scope.row)">
          <div class="folder" @click="openFile(scope.row)">
            <img v-if="scope.row.isFolder == 1" src="@/assets/classroom/folder.png" />

            <i class="el-icon-document-copy"></i>

            {{ scope.row.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="isFolder" label="是否目录" header-align="center" align="center" width="100">
        <template v-slot="scope">
          <el-tag v-if="scope.row.isFolder === 1" size="small" type="">目录</el-tag>
          <el-tag v-if="scope.row.isFolder === 0" size="small" type="">文件</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="type" label="文件类型" header-align="center" align="center" width="100">
        <template v-slot="scope">
          <el-tag v-if="scope.row.type === 1" size="small" type="">word</el-tag>
          <el-tag v-else-if="scope.row.type === 2" size="small" type="">video</el-tag>
          <el-tag v-else-if="scope.row.type === 3" size="small" type="">pdf</el-tag>
          <el-tag v-else size="small" type="">其他</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="链接地址" header-align="center" align="center"></el-table-column>
      <el-table-column prop="url" label="下载" header-align="center" align="center" width="100">
        <template v-slot="scope">
          <el-button size="small" type="primary" @click="downFile(scope.row.url, scope.row.name)">下载</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="size" label="单位（M）" header-align="center" align="center" width="100">
        <template #default="scope"> {{ Math.round(scope.row.sumSize / (1024 * 1024)) }}M </template>
      </el-table-column>

      <el-table-column prop="sort" label="排序" header-align="center" align="center" width="100"></el-table-column>
      <!--      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('fii:fiispace:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('fii:fiispace:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./fiispace-add-or-update.vue";
import baseService from "@/service/baseService";
export default defineComponent({
  components: {
    AddOrUpdate
  },
  setup() {
    const state = reactive({
      getDataListURL: "/fii/fiispace/page",
      getDataListIsPage: true,
      exportURL: "/fii/fiispace/export",
      deleteURL: "/fii/fiispace",
      deleteIsBatch: true,
      dataForm: {
        title: "",
        eq_pid_int: 0
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {},
  methods: {
    openFile(row: any) {
      if (row.isFolder == 1) {
        this.dataForm.eq_pid_int = row.id;
        this.query();
        console.log(row);
      }
    },
    /**
     * 返回上一级
     */
    backPath() {
      baseService.get("fii/fiispace/page", { eq_id_int: this.dataForm.eq_pid_int }).then((res) => {
        this.dataForm.eq_pid_int = res.data.list[0].pid;
        this.query();
      });
    },
    downFile(url: string, name: string) {
      baseService.downloadOss(url, {}, name);
    }
  }
});
</script>
